package com.sinopec.android.service;


import com.sinopec.android.HomeActivity;
import com.sinopec.android.util.LogUtil;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.widget.RemoteViews;

/**
* @ClassName: NotificationService
* @Description: TODO(后台service)
* @author liuwei
* @date 2012-6-5 上午10:41:06
* 
*/
public class NotificationService extends Service {
	private Context mContext = this;
    private NotificationManager mNotificationManager;  
    private Notification mNotification; 
    final int pullDelay = 60000;//检查配置更新服务的延迟时间间隔   单位ms  1分钟间隔
	 Handler handlerZoom = new Handler(){
	    	public void handleMessage(android.os.Message msg) {

	    	}
	    };
	 Handler handler = new Handler(){
	    	public void handleMessage(android.os.Message msg) {
	    		switch (msg.what) {
				case 1:
//					createNotification();
					
					break;

				default:
					break;
				}
	    	}
	    };   
	    Runnable pullChecker = new Runnable()
	    {
	        public void run()
	        {
	        	LogUtil.printInfo("NotificationService运行了.....");
	        	//1、调用pull接口
	        	//2、将返回结果，以通知形式展示
	        		handler.sendEmptyMessage(1);
	        	//3、点击通知，进入程序首页
	        	handlerZoom.removeCallbacks(pullChecker);
	            handlerZoom.postDelayed(pullChecker, pullDelay); // register a new one
	        }
	    };
	@Override
	public void onCreate() {
		LogUtil.printInfo("启动pull消息服务");
		super.onCreate();
	}

	@Override
	public void onDestroy() {
		LogUtil.printInfo("销毁pull消息服务");
		super.onDestroy();
	}

	@Override
	public void onStart(Intent intent, int startId) {
	    handlerZoom.postDelayed(pullChecker, pullDelay);
		mNotificationManager = (NotificationManager) getSystemService(android.content.Context.NOTIFICATION_SERVICE);
		super.onStart(intent, startId);
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}
	
	void createNotification(){
//		 int icon = R.drawable.download_icon;  
//	     CharSequence tickerText = fileName+"开始下载";  
//	     long when = System.currentTimeMillis();  
//	     mNotification = new Notification(icon, tickerText, when);  
//	  
//	        // 放置在"正在运行"栏目中   
//	     mNotification.flags = Notification.FLAG_ONGOING_EVENT;  
//	  
//	     RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.download_notification_layout);  
//	     contentView.setTextViewText(R.id.fileName, "正在下载"+fileName  );  
//	        
//	        // 指定个性化视图   
//	     mNotification.contentView = contentView;  
//	  
//	     Intent intent = new Intent(mContext, HomeActivity.class);  
//	     PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);  
//	        // 指定内容意图   
//	     mNotification.contentIntent = contentIntent;  
	}

}
